/*	This file is part of LSAC.

	LSAC is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	LSAC is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with LSAC.  If not, see <http://www.gnu.org/licenses/>.

	Copyright (c) 2010 LEPESME "Jiboo" Jean-Baptiste
*/

#include "cToken.h"
#include "lsac.h"

cToken::cToken(cLocation pLocation, string pValue)
{
	this->dLocation = pLocation;
	this->dValue = pValue;
}

cToken::~cToken()
{
	//LOG("deleting " << this);
}

cToken::cToken(unsigned int pLine, unsigned int pColumn, char pChar)
{
	this->dLocation.dLine = pLine;
	this->dLocation.dColumn = pColumn;
	this->dValue = pChar;
}

void cToken::addChar(char pChar)
{
	this->dValue += pChar;
}

bool cToken::operator==(string pCmp)
{
	return this->dValue == pCmp;
}

bool cToken::operator!=(string pCmp)
{
	return this->dValue != pCmp;
}

bool cToken::match(regex &pRegex)
{
	return regex_match(this->dValue, pRegex);
}

int cToken::toInt()
{
	return atoi(this->dValue.c_str());
}

bool cToken::toBool()
{
	return this->dValue == "vrai" ? true : false;
}

ostream& operator<<(ostream& o, const cToken& pToken)
{
	return o << "cToken(" << pToken.dLocation << ", '" << pToken.dValue << "')";
}

ostream& operator<<(ostream& o, const cToken* pToken)
{
	return o << "cToken(" << pToken->dLocation << ", '" << pToken->dValue << "')";
}
